The two main scripts that paper results are based on are run_K_sims.R and case_study.R. 


run_K_sims.R -- used to run a small number of simulated trials on a single core. 
    - It is designed to be run many times on a SLURM cluster (using an sbatch script like scenario_1_high.sbatch). It can also be used outside of a SLURM job, in which case the simulation scenario details must be set in the script on lines 26-28. 
    - All of the hard-coded filepaths in this script and elsewhere in the code are relative to the spx_paper_code directory, so if the working directory when run_K_sims.R is run is not spx_paper_code then the path to it must be supplied by modifying line 2. 
    - It saves the run trials in the working directory, though the location can be changed by modifying line 45
    - It sources other helper scripts, some of which load various required R packages which need to be installed before the code can run.


case_study.R -- runs the case study analyses from Section 5 of the paper.
    - It also assumes that the working directory is spx_paper_code.


Other scripts included are:
    data_setup.R -- objects and functions needed to sample trial data
    jags_functions.R -- function to run a JAGS model on trial data
    make_scrambled_data.R -- make historical data for Scenarios 2 and 4 based on 1 and 3 (permuting covariates and response rates)
    models_list.R -- object specifying JAGS models used to run/analayze trials
    scenario_1_high.sbatch -- example sbatch script to run the full simulations on a SLURM cluster
    sim_analysis_functions.R -- functions to read raw simulation results (including posterior MCMC for each replicate) and return summary metrics
    sim_analysis.R -- key script to analyze simulation results
    two_stage.R -- function to run a two-stage adaptive trial using various models
	

The various JAGS model scripts are in the jags subdirectory.


The data subdirectory contains the historical data used for each of the four basic simulation scenarios as well as the historical data set for the case study.
